<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitealbum
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: _photoView.tpl 2011-08-026 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
?>
<script type="">
var is_location_ajax = '<?php echo $this->isajax;?>';
</script>
<?php
  $this->headScript()
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Observer.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.Local.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.Request.js')
    ->appendFile($this->layout()->staticBaseUrl . 'application/modules/Seaocore/externals/scripts/tagger/tagger.js')
    ->appendFile($this->layout()->staticBaseUrl . 'application/modules/Album/externals/scripts/core.js');
  $this->headTranslate(array(
    'Save', 'Cancel', 'delete',
  ));
?>
<?php 
  $fbmodule = Engine_Api::_()->getDbtable('modules', 'core')->getModule('facebookse');
  if (empty ($fbmodule) || empty($fbmodule->enabled) || $fbmodule->version <=  '4.2.3')
   $enable_facebookse = 0;
   
  else 
     $enable_facebookse = 1;
?>
<div id="layout_middle">
<!--FACEBOOK LIKE BUTTON START HERE-->
  <?php if ($enable_facebookse) :?>
    <div >
         <script type="text/javascript">
            var fblike_moduletype = 'album_photo';
						var fblike_moduletype_id = '<?php echo $this->photo->getIdentity(); ?>'
          </script>
          <?php echo '<br />' . Engine_Api::_()->facebookse()->isValidFbLike('album')  ; ?>
        </div>
  <?php endif; ?> 
<div class='albums_viewmedia'>
  <?php if (!$this->message_view):?>
  <div class="albums_viewmedia_nav">
    <div>
      <?php echo $this->translate('Photo %1$s of %2$s in %3$s',
          $this->locale()->toNumber($this->getPhotoIndex  + 1),
          $this->locale()->toNumber($this->album->count()),
          (string) $this->album->getTitle()) ?>
    </div>
    <?php if ($this->album->count() > 1): ?>
    <div>
      <a href="<?php echo $this->escape($this->previousPhoto->getHref())  ?>" onclick="photoPaginationDefaultView('<?php echo $this->escape($this->previousPhoto->getHref())  ?>' ); return false;"  title="<?php echo $this->translate('Previous');?>" > <?php echo $this->translate('Previous') ?></a>
  		<a href="<?php echo $this->escape($this->nextPhoto->getHref()) ?>" onclick="photoPaginationDefaultView('<?php echo $this->escape($this->nextPhoto->getHref()) ?>'); return false;"  title="<?php echo $this->translate('Next');?>" ><?php echo $this->translate('Next'); ?></a>

    </div>
    <?php endif; ?>
  </div>
  <?php endif;?>
  <div class='albums_viewmedia_info'>
    <div class='album_viewmedia_container' id='media_photo_div'>
      
      <a id='media_photo_next'   <?php if ($this->album->count() > 1): ?> href='<?php echo $this->escape($this->nextPhoto->getHref()) ?>' onclick="photoPaginationDefaultView('<?php echo $this->escape($this->nextPhoto->getHref()) ?>'); return false;" <?php endif; ?> >
      
      <?php echo $this->htmlImage($this->photo->getPhotoUrl(), $this->photo->getTitle(), array(
          'id' => 'media_photo',
        )); ?>     
      </a>     
    </div>
    <br />
    <a></a>
    <?php if($this->enablePinit): ?>
	  <div class="seaocore_pinit_button">
	  	<a href="http://pinterest.com/pin/create/button/?url=<?php urlencode(((!empty($_ENV["HTTPS"]) && 'on' == strtolower($_ENV["HTTPS"])) ? "https://":"http://") . $_SERVER['HTTP_HOST'].$this->photo->getHref()); ?>&media=<?php  echo urlencode(((!empty($_ENV["HTTPS"]) && 'on' == strtolower($_ENV["HTTPS"])) ? "https://":"http://") . $_SERVER['HTTP_HOST'].$this->photo->getPhotoUrl()); ?>&description=<?php echo $this->photo->getTitle(); ?>" class="pin-it-button" count-layout="horizontal"  id="new_pin" >Pin It</a>
			<script type="text/javascript" >
			   en4.core.runonce.add(function() {              
			      new Asset.javascript( 'http://assets.pinterest.com/js/pinit.js',{});                 
			   });			 
			</script>
	  </div>
   <?php endif;?>
    <?php echo $this->socialShareButton();?> 
    <?php if( $this->photo->getTitle() ): ?>
      <div class="albums_viewmedia_info_title">
        <?php echo $this->photo->getTitle(); ?>
      </div>
    <?php endif; ?>
    <?php if( $this->photo->getDescription() ): ?>
      <div class="albums_viewmedia_info_caption">
        <?php echo nl2br($this->photo->getDescription()) ?>
      </div>
    <?php endif; ?>
		<?php if (Engine_Api::_()->getDbtable('modules', 'core')->isModuleEnabled('sitetagcheckin')) :?>
			<div class="seaotagcheckinshowlocation">
				<?php
					// RENDER LOCAION WIDGET
					echo $this->content()->renderWidget("sitetagcheckin.location-sitetagcheckin", array('showSuggest'=> 0)); 
				?>
			</div>
		<?php endif;?>
    <div class="albums_viewmedia_info_tags" id="media_tags" style="display: none;">
      <?php echo $this->translate('In this photo:') ?>
    </div>
    <div class="albums_viewmedia_info_footer">
      <?php if ($this->canMakeFeatured && !$this->allowView): ?>
        <div class="tip">
          <span>
            <?php echo $this->translate("SITEALBUM_PHOTO_VIEW_PRIVACY_MESSAGE"); ?>
          </span>
        </div>
      <?php endif; ?>
      <div class="albums_viewmedia_info_date">
        <?php echo $this->translate('Added %1$s', $this->timestamp($this->photo->modified_date)) ?>
        <?php if( $this->canTag ): ?>
          - <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Tag This Photo'), array('onclick'=>'taggerInstance.begin();')) ?>
        <?php endif; ?>
        <?php if( $this->canEdit ): ?>
          - <?php echo $this->htmlLink(array('reset' => false, 'action' => 'edit'), $this->translate('Edit'), array('onclick'=>"showSmoothBox('".$this->escape($this->url(array('action' => 'edit')))."'); return false;")) ?>
        <?php endif; ?>
        <?php if( $this->canDelete ): ?>
          - <?php echo $this->htmlLink(array('reset' => false, 'action' => 'delete'), $this->translate('Delete'), array('onclick'=>"showSmoothBox('".$this->escape($this->url(array('action' => 'delete')))."'); return false;")) ?>
        <?php endif; ?>
        <?php if( !$this->message_view ):?>
          <?php if( SEA_PHOTOLIGHTBOX_SHARE ):?>
        - <a href="<?php echo $this->url(Array('module'=> 'activity', 'controller' => 'index', 'action' => 'share',  'type' => 'album_photo', 'id' => $this->photo->getIdentity(), 'format' => 'smoothbox'), 'default' , true); ?>" onclick="showSmoothBox('<?php echo $this->escape($this->url(array('module'=> 'activity', 'controller' => 'index', 'action' => 'share','type' => 'album_photo', 'id' => $this->photo->getIdentity(), 'format' => 'smoothbox'), 'default' , true)); ?>'); return false;" > <?php echo $this->translate("Share") ?></a>
          <?php endif;?>
          <?php if( SEA_PHOTOLIGHTBOX_REPORT ):?>
        - <a href="<?php echo $this->url(Array('module'=> 'core', 'controller' => 'report', 'action' => 'create',  'subject' => $this->photo->getGuid(), 'format' => 'smoothbox'), 'default' , true); ?>" onclick="showSmoothBox('<?php echo ($this->url(array('module'=> 'core', 'controller' => 'report', 'action' => 'create',  'subject' => $this->photo->getGuid(), 'format' => 'smoothbox'), 'default' , true)); ?>'); return false;" > <?php echo $this->translate("Report") ?></a>
         <?php endif;?>
         <?php if( SEA_PHOTOLIGHTBOX_MAKEPROFILEPHOTO ):?>
        - <a href="<?php echo $this->url(Array('controller' => 'edit', 'action' => 'external-photo', 'photo' => $this->photo->getGuid(), 'format' => 'smoothbox'), 'user_extended' , true); ?>" onclick="showSmoothBox('<?php echo $this->escape($this->url(Array( 'controller' => 'edit', 'action' => 'external-photo', 'photo' => $this->photo->getGuid(), 'format' => 'smoothbox'), 'user_extended' , true)); ?>'); return false;" > <?php echo $this->translate("Make Profile Photo") ?></a>
         <?php endif; ?>
         <?php if( SEA_PHOTOLIGHTBOX_DOWNLOAD ):?>
        <iframe src="about:blank" style="display:none" name="downloadframe"></iframe>
        - <a href="<?php echo $this->url(array('module' => 'seaocore', 'controller' => 'core', 'action' => 'download'), 'default', true); ?><?php echo '?path=' . urlencode($this->photo->getPhotoUrl()).'&file_id='.$this->photo->file_id ?>" target='downloadframe'><?php echo $this->translate('Download')?></a>
          <?php endif;?>
        <?php endif;?>       
       <?php if( $this->canMakeFeatured && $this->allowView ): ?>
        - <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Make Photo of the Day'), array('onclick'=>"showSmoothBox('".$this->escape($this->url(array('controller'=>'photo','action' => 'add-photo-of-day','photo_id'=>$this->subject()->getIdentity()),'sitealbum_extended',true))."'); return false;")) ?>
        - <a href="javascript:void(0);"  onclick='featuredPhoto();' ><span id="featured_sitealbum_photo" <?php if($this->subject()->featured): ?> style="display:none;" <?php endif;?> title="<?php echo $this->translate("Make Featured"); ?>" ><?php echo $this->translate("Make Featured"); ?> </span> <span id="un_featured_sitealbum_photo" <?php if(!$this->subject()->featured): ?> style="display:none;" <?php endif;?> title="<?php echo $this->translate("Make Un-Featured"); ?>" > <?php echo $this->translate("Make Un-featured"); ?> </span></a>
       <?php endif;?>
      </div>      
      <?php if( $this->canEdit ): ?>
      <div class="albums_viewmedia_info_actions">
        <a class="buttonlink icon_photos_rotate_ccw" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.rotate(<?php echo $this->photo->getIdentity() ?>, 90).addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_rotate_ccw') }.bind(this));" title="<?php echo $this->translate("Rotate Left"); ?>">&nbsp;</a>
        <a class="buttonlink icon_photos_rotate_cw" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.rotate(<?php echo $this->photo->getIdentity() ?>, 270).addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_rotate_cw') }.bind(this));" title="<?php echo $this->translate("Rotate Right"); ?>" >&nbsp;</a>
        <a class="buttonlink icon_photos_flip_horizontal" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.flip(<?php echo $this->photo->getIdentity() ?>, 'horizontal').addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_flip_horizontal') }.bind(this));" title="<?php echo $this->translate("Flip Horizontal"); ?>" >&nbsp;</a>
        <a class="buttonlink icon_photos_flip_vertical" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.flip(<?php echo $this->photo->getIdentity() ?>, 'vertical').addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_flip_vertical') }.bind(this));" title="<?php echo $this->translate("Flip Vertical"); ?>">&nbsp;</a>
      </div>
      <?php endif ?>
     
    </div>
  </div>
   
  <?php //RENDER FACEBOOK COMMENT WIDGET IF HE HAS ENABLED THIS.
  
        if ($enable_facebookse) { 
			
			 if (Engine_Api::_()->facebookse()->showFBCommentBox ('album') != 1) {
				echo $this->action("list", "comment", "core", array("type"=>"album_photo", "id"=>$this->photo->getIdentity())); 
			 }
			if(Engine_Api::_()->facebookse()->showFBCommentBox ('album')) {  
			  $curr_url = ( _ENGINE_SSL ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
			  echo $this->content()->renderWidget("facebookse.facebookse-comments", array('module_type' => 'album_photo', 'curr_url' => $curr_url, 'subject' => $this->subject()->getGuid(), 'task' => 1, 'type' => 'album_photo', 'id' => $this->photo->getIdentity()));
			}	
			
	    }
	    else {
			echo $this->action("list", "comment", "core", array("type"=>"album_photo", "id"=>$this->photo->getIdentity()));
			
		}
        
        
        ?>
</div>
</div>

<script type="text/javascript">
  var taggerInstance;
  var defaultLoad=true;
  var existingTags=<?php echo $this->action('retrieve', 'tag', 'core', array('sendNow' => false)) ?>;
  function getTaggerInstanceSitealbum(){
  taggerInstance = new SEAOTagger('media_photo_next', {
    'title' : '<?php echo $this->string()->escapeJavascript($this->translate('Tag This Photo')); ?>',
    'description' : '<?php echo $this->string()->escapeJavascript($this->translate('Type a tag or select a name from the list.')); ?>',
    'createRequestOptions' : {
      'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'add'), 'default', true) ?>',
      'data' : {
        'subject' : '<?php echo $this->subject()->getGuid() ?>'
      }
    },
    'deleteRequestOptions' : {
      'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'remove'), 'default', true) ?>',
      'data' : {
        'subject' : '<?php echo $this->subject()->getGuid() ?>'
      }
    },
    'cropOptions' : {
      'container' : $('media_photo_next')
    },
    'tagListElement' : 'media_tags',
    'existingTags' : existingTags,
    'suggestProto' : 'request.json',
    'suggestParam' : "<?php echo $this->url(array('module' => 'user', 'controller' => 'friends', 'action' => 'suggest', 'includeSelf' => true), 'default', true) ?>",
    'guid' : <?php echo ( $this->viewer()->getIdentity() ? "'" . $this->viewer()->getGuid() . "'" : 'false' ) ?>,
    'enableCreate' : <?php echo ( $this->canTag ? 'true' : 'false') ?>,
    'enableDelete' : <?php echo ( $this->canUntagGlobal ? 'true' : 'false') ?>
  });

  var onclickNext = $('media_photo_next').getProperty('onclick');
  taggerInstance.addEvents({
    'onBegin' : function() {
      $('media_photo_next').setProperty('onclick','return false;');
    },
    'onEnd' : function() {
      $('media_photo_next').setProperty('onclick',onclickNext);
    },
    'onCreateTag': function(params) {      
      existingTags.push(params);
    },
    'onRemoveTag' : function(id) {       
      for(var i=0; i< existingTags.length; i++) {         
        if(existingTags[i].id == id) {           
          existingTags.splice(i, 1);
          break;
        }
      }
    }
  });
  }
  en4.core.runonce.add(function() {
    var descEls = $$('.albums_viewmedia_info_caption');
    if( descEls.length > 0 ) {
      descEls[0].enableLinks();
    }
    
    setTimeout("getTaggerInstanceSitealbum()",1250);
  });

  window.addEvent('keyup', function(e) {
    if(defaultLoad){ 
      if( e.target.get('tag') == 'html' ||
        e.target.get('tag') == 'body' ) {
        if( e.key == 'right' ) {
          photoPaginationDefaultView(getNextPhotoDefault());
        } else if( e.key == 'left' ) {
          photoPaginationDefaultView(getPrevPhotoDefault());
        }
      }
    }
  });

  function getPrevPhotoDefault(){
    return '<?php echo $this->escape($this->previousPhoto->getHref()) ?>';
  }
  function getNextPhotoDefault(){
    return '<?php echo $this->escape($this->nextPhoto->getHref()) ?>';
  }

  var photoPaginationDefaultView = function(url)
  {
    if (history.pushState)
      history.pushState( {}, document.title, url );
    else{
      window.location.hash =url;
    }
    $('media_photo').src = "<?php echo $this->layout()->staticBaseUrl ?>application/modules/Sitealbum/externals/images/loader.gif";
    $('media_photo').style.marginTop='150px';
    en4.core.request.send(new Request.HTML({
      url : url,
      data : {
        format : 'html',
        isajax : 1
      },
      onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {       
        $('default_image_div').innerHTML = responseHTML;
        
        if (typeof FB != 'undefined') {
           FB.XFBML.parse();
        }
      }
    }));
  };
  function showSmoothBox(url)
  {

    Smoothbox.open(url);
    parent.Smoothbox.close;
  }
</script>
<script type="text/javascript">
  function featuredPhoto()
  { 
    en4.core.request.send(new Request.HTML({
      method : 'post',
      'url' : en4.core.baseUrl + 'sitealbum/photo/featured',
      'data' : {
        format : 'html',
        'subject' : '<?php echo $this->subject()->getGuid() ?>'
      },
      onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {
       if($('featured_sitealbum_photo').style.display=='none'){
        $('featured_sitealbum_photo').style.display="";
        $('un_featured_sitealbum_photo').style.display="none";
       }else{
          $('un_featured_sitealbum_photo').style.display="";
        $('featured_sitealbum_photo').style.display="none";
       }
      }
    }));

    return false;

  }
</script>
